package com.wq.stock.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.wq.common.api.model.stock.StockSku;
import com.wq.common.api.service.stock.StockMerchandiseService;
import com.wq.stock.service.StockSkuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class StockMerchandiseServiceImpl implements StockMerchandiseService {

    @Autowired
    private StockSkuService stockSkuService;

    @Override
    public boolean reduceStocks(StockSku stockSku) {
        UpdateWrapper<StockSku> updateWrapper = new UpdateWrapper<StockSku>();
        updateWrapper.eq("sku_id", stockSku.getSkuId());
        updateWrapper.eq("ware_id", stockSku.getWareId());
        updateWrapper.setSql("stock_locked = stock_locked + "+ stockSku.getStockLocked());
        updateWrapper.setSql("stock = stock - "+ stockSku.getStockLocked());
        boolean update = stockSkuService.update(updateWrapper);
        return update;
    }
}
